<template>
  <el-main class="right">
    <div class="mainHeader">
      <div class="head-con">
        <div class="left">
          <div class="content-icon" @click.prevent="collapseBtn">
            <!-- <i v-show="isCollapse" class="el-icon-menu"></i>
            <i v-show="!isCollapse" class="el-icon-s-fold"></i> -->
            <i class="el-icon-s-unfold" v-show="!isCollapse" style="font-size:22px;color:#fdfdfd"></i>
            <i class="el-icon-s-fold" v-show="isCollapse" style="font-size:22px;color:#fdfdfd"></i>
          </div>
          <!-- <i class="el-icon-s-unfold" style="font-size:22px;color:#fdfdfd"></i> -->
          <el-input class="sousuo" placeholder="搜索菜单" v-model="input2">
          </el-input>
        </div>
        <div class="right">
          <img class="img" src="../assets/img/headImg.jpg" alt="">
          <el-dropdown>
            <span class="el-dropdown-link" style="margin-left:8px">
              超级管理员<i class="el-icon-arrow-down el-icon--right"></i>
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item @click.native="dialogVisible=true">修改密码</el-dropdown-item>
              <el-dropdown-item @click.native="logout">退出登录</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </div>
      </div>
      <div class="main">
        <router-view></router-view>
      </div>
    </div>

    <!-- 修改密码弹窗 -->
    <el-dialog title="修改密码" :visible.sync="dialogVisible" width="30%" :before-close="handleClose">
      <template>
        <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="80px">
          <el-form-item label="原密码" prop="oldPass">
            <el-input placeholder="请输入原密码" clearable v-model.trim="ruleForm.oldPass" type="password"></el-input>
          </el-form-item>

          <el-form-item label="新密码" prop="newPass">
            <el-input placeholder="请输入新的密码" clearable v-model.trim="ruleForm.newPass" type="password"></el-input>
          </el-form-item>

          <el-form-item label="确认密码" prop="newPass2">
            <el-input placeholder="请再次输入新的密码" clearable v-model.trim="ruleForm.newPass2" type="password"></el-input>
          </el-form-item>
        </el-form>
      </template>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>
  </el-main>
</template>

<script>
export default {
  data() {
    return {
      input2: '',
      dialogVisible: false,
      ruleForm: {
        oldPass: '',
        newPass: '',
        newPass2: ''
      },
      rules: {
        oldPass: [
          { required: true, message: '请输入原密码', trigger: 'blur' }
        ],
        newPass: [
          { required: true, message: '请输入新的密码', trigger: 'blur' }
        ],
        newPass2: [
          { required: true, message: '请再次输入密码', trigger: 'blur' }
        ]
      }
    }
  },
  computed: {
    // eslint-disable-next-line vue/no-dupe-keys
    isCollapse() {
      return this.$store.state.isCollapse
    }
  },
  methods: {
    //  修改密码
    handleClose(done) {
      this.$confirm('确认关闭？')
        .then(_ => {
          done()
        })
        .catch(_ => { })
    },
    // 登出
    logout() {
      console.log(11)
      this.$confirm('你确定要退出登录吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$router.push({
          path: '/'
        })
        this.$message({
          message: '退出成功',
          type: 'success'
        })
      }).catch(() => {
        this.$message({
          message: '取消成功',
          type: 'success'
        })
      })
    },
    // 左侧导航滑动事件
    collapseBtn() {
      this.$store.commit('collapseBtn')
    }
  }
}
</script>

<style lang="less" scoped>
.right {
  // background-color: #e9eef3;
  // color: #333;
  padding: 0;
  // line-height: 60px;
  .mainHeader {
    height: 60px;
    background: #545c64;
    .head-con {
      padding: 0 20px;
      display: flex;
      justify-content: space-between;
      align-items: center;
      .left {
        width: 200px;
        height: 60px;
        display: flex;
        justify-content: space-around;
        align-items: center;
        .sousuo {
          display: inline-block;
          margin-left: 8px;
          /deep/ .el-input__inner {
            height: 26px;
          }
        }
      }
      .right {
        width: 160px;
        height: 60px;
        display: flex;
        align-items: center;
        .img {
          width: 40px;
          height: 40px;
          border-radius: 50%;
        }
        .el-dropdown-link {
          cursor: pointer;
          color: #fdfdfd;
        }
        .el-icon-arrow-down {
          font-size: 16px;
        }
      }
    }
    .main {
      margin: 20px 20px 0 20px;
    }
  }
}
</style>
